package com.minisoft.jd.normal;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.thread.ThreadUtil;
import com.minisoft.utils.HttpClientService;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;

import java.io.IOException;

/**
 * @author JueSu
 * @description: TODO
 * @date 2024/4/22 10:12
 */
@Slf4j
public class QiangGou {

    public static void main(String[] args) throws IOException {
        //5个线程跑
        for (int i = 1; i <= 1; i++) {
            ThreadUtil.execute(() -> {
                for (int j = 5; j <= 1000; j++) {
                    try {
//            huaweiPura70Pro();
                        suningMaotai();
                        ThreadUtil.sleep(200);
                    } catch (IOException e) {
                        log.error("qiang gou error", e);
                    }
                }
            });
        }
    }


    /**
     * HUAWEI Pura 70 Pro(10:08)
     * @return
     */
    public static void huaweiPura70Pro() throws IOException {
        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
        RequestBody body = RequestBody.create(mediaType, "num=1&addressId=137909159&name=潘女士&provinceId=19&provinceName=广东&cityId=1657&cityName=中山市&countyId=3001&countyName=坦洲镇&townId=0&townName=&addressDetail=锦绣国际花城1期23栋1701&mobile=135****7058&mobileKey=bda0b256991beeb103876d3ae7fdbf43&email=&invoiceTitle=4&invoiceContent=1&invoicePhone=135****7058&invoicePhoneKey=bda0b256991beeb103876d3ae7fdbf43&invoice=true&password=&codTimeType=3&paymentType=4&overseas=0&phone=&areaCode=86&token=4cd55881889842c7141f9be859a5c5b9&skuId=100095516785&h5st=20240422100958736;6ne56qftn5ut1l12;9da72;tk03w9dcc1b6118nZJzS7lq60ucsreFmkBiHlXHWA0cGKrRRZ-OXW3KI7OOoBXTMs7knB-aLIPwK8Cd8OnsCCh3qv25X;f504528f0b8a229caaa81a1f1c1e770936ce46f28e36bdbf056c5b145ec48ecf;4.3;1713751798736;7e3825f52a44b4980ebfc391d6db06af095aa88009d38eb9f779ed0e0c89675c814997883fb0c6739b62880d528721aed237e15d26324f85d1cae81603ae45af6eeb8bf8795c46b7805a99d727cce6ed344d58d12e4a71538c5ae58acd12968456ba2402f53c93b999567d005d9334de56fb3b5a5b707f57ea47749ffc27cd13fbc949ec1967e4f32f7c2b99c5443096d72096bbd94ea35b2bc7c439af2e9cfc5d2032ff660a9efc9ac84c452d8e3fc3c999846832af14db10b51f053c39c4a3ac8465c20b211df411cf3c0a4417c56a9611fa1f821f3982e0d736909b2cea62c0ff5e0356632add1ec252037fe8fd3dfd1f1bddeb87ea2811fa4176c4838680670e7f669b6b28789802224f6754faae2baac5239fdedded8de87291a03e0f3b6307e5df39f2a73c31cef0c886a0863806cd755703f6324c76b9f9c71eaefc9c&_stk=addressDetail,addressId,areaCode,cityId,cityName,codTimeType,countyId,countyName,email,invoice,invoiceContent,invoicePhone,invoicePhoneKey,invoiceTitle,mobile,mobileKey,name,num,overseas,password,paymentType,phone,provinceId,provinceName,skuId,token,townId,townName&eid=jdd033SG5N4KF7EISZ2CQI2W5FTSJKQEZWETAV6FVJLQ4NY5K5VF6X4B7DX5GOETLUCOHJDXE5MVYEYJVNWBEJN7TU3GN74AAAAMPAOHXXPQAAAAACOMP3EPGRU2MA4X");
        Request request = new Request.Builder()
                .url("https://marathon.jd.com/seckillnew/orderService/submitOrder.action?skuId=100095516785")
                .method("POST", body)
                .addHeader("Host", "marathon.jd.com")
                .addHeader("accept", "application/json, text/plain, */*")
                .addHeader("x-rp-client", "h5_1.0.0")
                .addHeader("User-Agent", "jdapp;android;12.4.0;;;M/5.0;appBuild/99084;ef/1;ep/%7B%22hdid%22%3A%22JM9F1ywUPwflvMIpYPok0tt5k9kW4ArJEU3lfLhxBqw%3D%22%2C%22ts%22%3A1713751683335%2C%22ridx%22%3A-1%2C%22cipher%22%3A%7B%22sv%22%3A%22CJK%3D%22%2C%22ad%22%3A%22CJqzDJuzEJS1ENLuCNPvCq%3D%3D%22%2C%22od%22%3A%22CNKmCNKmCNKjCNKmCM0mCNKmBJKmCNKjCNKmCNKmCNKmCNKm%22%2C%22ov%22%3A%22Ctu%3D%22%2C%22ud%22%3A%22CJqzDJuzEJS1ENLuCNPvCq%3D%3D%22%7D%2C%22ciphertype%22%3A5%2C%22version%22%3A%221.2.0%22%2C%22appname%22%3A%22com.jingdong.app.mall%22%7D;jdSupportDarkMode/0;Mozilla/5.0 (Linux; Android 10; BMH-AN10 Build/HUAWEIBMH-AN10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/89.0.4389.72 MQQBrowser/6.2 TBS/046283 Mobile Safari/537.36")
                .addHeader("x-referer-page", "https://marathon.jd.com/seckillM/seckill.action")
                .addHeader("Origin", "https://marathon.jd.com")
                .addHeader("X-Requested-With", "com.jingdong.app.mall")
                .addHeader("Sec-Fetch-Site", "same-origin")
                .addHeader("Sec-Fetch-Mode", "cors")
                .addHeader("Sec-Fetch-Dest", "empty")
                .addHeader("Referer", "https://marathon.jd.com/seckillM/seckill.action?skuId=100095516785&num=1&rid=1713751684&deliveryMode=")
                .addHeader("Accept-Language", "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7")
                .addHeader("Cookie", "shshshfpa=c4e9c702-4e8f-6a4f-9e09-a6819cd21ba9-1627119916; __jdu=16390397454101462430946; shshshfp=4ae35d2051f7bc4d990348c9bc20a1f7; shshshfpx=c4e9c702-4e8f-6a4f-9e09-a6819cd21ba9-1627119916; pinId=EvE-50nGwH3ZTlS-EiSWPA; pin=juesuchen; unick=jue_jue; _tp=uJs1qGio5uDIOiZ1tFsPbw%3D%3D; _pst=juesuchen; user-key=da9f32b5-7fd5-4b53-921c-5d797c2a2022; ipLocation=%u5e7f%u4e1c; areaId=19; TrackID=189fdu6F_t3xvkrVUVyuBfoBt6WBppykbFqtbgM7s9uddm10GBGlOFGL1TBEK7ZMmKl7AHEhploeVqrF0uJhi1vaQNWfvgmB0myqwexfBbsI; thor=A6B163847E03FD546F3BF4599CDE88FE37B7341BDB01DD108C88B446CB18538AE345F4773E1D32FE853CA4327DC2E2785282C820BCB2A8ED19D4AF8133360F15156701DE39302C5789DC095AA7878C619D80193E0445313D3CB311FCE8ED98F45474CEDEE2A1B55B1E8AC5CED93A6F74DF8D46C181C564E4DBD1022D5C50261DE885DB544944FFCF638AF97FF9FAB881; flash=2_txXoZYF4VTdLjrh7psnnFvd83llaIAHr-KxUCv0iwPwMVbqETa-G7OfwLAU8uxdCI2aOGr6qRg3vc3cPal_iYvno4GA8-2C--1mSQZbkgJo*; ipLoc-djd=19-1657-3001-0.137909159; PCSYCityID=CN_440000_442000_0; cn=21; mba_muid=16390397454101462430946; warehistory=\"100107613718,\"; wxa_level=1; retina=1; cid=9; wqmnx1=MDEyNjM1M3BpbWNydDEzaHVzbG1hPWVSVExCWEdFPXhHeC1EaDlFNDBmWWN1ZDBtcm90ZGplbXA9MzUzOF89MzQxNTgxMWwuaXMxIDQ0cGI1NlRsRylvMTBhLzMyczRVLTUxT0NIKigp; jxsid=17139300677139874478; appCode=ms0ca95114; webp=1; visitkey=6604584538469258085; mba_sid=17139300678668390735222497574.1; cd_eid=jdd03OMIJOWZ3QL6G537C6AMOJEXLTWBG2DLOPREHKBDLDV52NWIWOF54VDTQ5HQM76LS4EHTL4LQS72AT3AD5VBRPN47CIAAAAMPAPQHCYQAAAAADYKUJCWYUEVH7MX; equipmentId=OMIJOWZ3QL6G537C6AMOJEXLTWBG2DLOPREHKBDLDV52NWIWOF54VDTQ5HQM76LS4EHTL4LQS72AT3AD5VBRPN47CI; fingerprint=bd3da530304462f8acc15275ee0a0506; deviceVersion=119.0.0.0; deviceOS=; deviceOSVersion=; deviceName=Chrome; __wga=1713930068984.1713930068984.1713930068984.1713930068984.1.1; PPRD_P=UUID.16390397454101462430946-LOGID.1713930068989.233537504; sc_width=1280; __jd_ref_cls=MProductdetail_Normal; unpl=JF8EAK1nNSttUUJTUU9SHBYTGV9RWw9bQkRUP2FSAw5QHlwHGlYSFBh7XlVdWBRKEh9sYhRUXVNOVA4bCisSEXtdVV9cCkwWAmlmNWRaWEIZRElPKxEQe11Vbl0PSR8CbW8DUVldS1UFHgUYFxJKVVFZbQl7EANmVzVkWFhKVQIbCh4SFntcZFxcCU4XA2ZlBVVtEyVVSBsFGRoRSVVSW1kNSxYDamAGUV9ZQ1ECKwMrEQ; jsavif=1; __jdv=29846306|www.itab.link|t_1000360070_|tuiguang|886eea652c344cb8bfa7ffb9d930e879|1713930081526; 3AB9D23F7A4B3C9B=OMIJOWZ3QL6G537C6AMOJEXLTWBG2DLOPREHKBDLDV52NWIWOF54VDTQ5HQM76LS4EHTL4LQS72AT3AD5VBRPN47CI; token=fe007f44f5fe6e801ff46b8a6af6b29c,3,952183; __jda=181111935.16390397454101462430946.1639039745.1713930067.1713930081.90; __jdc=181111935; seckillSid=; seckillSku=100095516785; shshshfpb=BApXc4k06DepAH2kSvMiE-yzAz_YnFKpzB2VQnjlX9xJ1MsHWnYO2; 3AB9D23F7A4B3CSS=jdd03OMIJOWZ3QL6G537C6AMOJEXLTWBG2DLOPREHKBDLDV52NWIWOF54VDTQ5HQM76LS4EHTL4LQS72AT3AD5VBRPN47CIAAAAMPBY2B2EYAAAAADNKMW2NAX4LYN4X; _gia_d=1; __jdb=181111935.9.16390397454101462430946|90.1713930081")
                .addHeader("content-type", "application/x-www-form-urlencoded")
                .addHeader("Connection", "keep-alive")
                .build();
        Response response = client.newCall(request).execute();
        System.out.println(response.body().string());
    }

    /**
     * 苏宁茅台抢购 9.30
     */
    public static void suningMaotai() throws IOException {
        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded; charset=utf-8");
        RequestBody body = RequestBody.create(mediaType, "data={\"cartHeadInfo\":{\"userFlag\":\"0\",\"directFlag\":\"1\",\"operationChannel\":\"50\",\"operationTerminal\":\"01\",\"operationEquipment\":\"02\",\"operationUser\":\"\",\"token\":\"mqnWCMQ)TT6MTyXwaO2xfVXHhKHMW0tpWm836JgXTjA*\",\"detect\":\"mmds_a_._a0752c4c-23b5-4d3c-a8b5-c3eb326020b0_._bEEE3333333YLp3333cG.ex333333333YLp33YxGG.ex333333333YLs33YccGRex333Y33333YLr33DYGGWex3333Yp4jlthX334Kcbpex3333Yp4jlthX333RGbpex3333Yp4fvmLo33FkcHMex3333Yp4fvmLo33YWGHMex3333Yp4fvmLJ33YtcHtex3333Yp4fvmLJ33YNGHtex3333Yp4fvmLP33Y8cI_ex3333Yp4fvmLP33YmGI_ex333333333YLs33YycHOex3333Yp4fvmo4330vGHtex3333Yp4fvmoG33Y1cH6ex3333Yp4fvmoG333lGH6ex3333Yp4fvmLp33YyiHiex3333Yp4fvmLr33apcGpex3333Yp4fvmLr33YNGGpex3333Yp4fvmLs33Y8cHFex3333Yp4fvmLs33YUGHFex3333Yp4fvmo433YtcH0ex3333Yp4fvmo433YnGH0ex333333333YLZ33YtcH9ex3333Yp4fvmLs330_GH9ex3333Yp4fvmoI33Y8cHVex3333Yp4fvmoI33YaGHVex3333Yp4fvmLZ33YzcGZex3333Yp4fvmLZ33YNGGZex333333333YLM33YncHFex3333Yp4fvmLR330QGGOex3333Yp4fvmLT33YtcH0ex3333Yp4fvmLT33YxGH0ex3333Yp4fvmLP33YJcGpex3333Yp4fvmLP33YxGGpex3333Yp4fvmL533YJcH4ex3333Yp4fvmL533YtGH4ex333333333YLP33FicG5ex333333333YLP33YxGG5ex333333333YL.33YzcHVex333333333YL.33Y6GHVex333333333YLP33YucHhex333333333YLP33Y5GHhex3333Yp4jltiD33DJcbMex3333Yp4jltiD33YJGbMex3333Yp4fvmLz33FBcHUex3333Yp4fvmLz33Y0GHUex3333Yp4fvmLR33Y*cHmex3333Yp4fvmLR33YfGHmex3333Yp4fvmLl339dcH9ex3333Yp4fvmLl33Y3GH9ex3333Yp4fvmLT33FPicpex333333333YoX334*cGoex3333Yp4fvmoa33XvGGMex3333Yp4fvmoa33Y8cGMex3333Yp4fvmoa3332GGMex3333Yp4fvmoY33YycGZex3333Yp4fvmoY33YbGGZex333333333Yo033YmcHYex333333333Yo033YbGHYex333333333Yo933YucH0ex333333333Yo9333rGH0ex333333333YoJ334LcHKex333333333YoJ33YlGHKex333333333YLr33YzcHoex333333333YLr33YfGHoex33333Lxn0D33339D*3333333333333YoH33DbcHJex333333333YoI330FGH8ex333333333YLr33Y8cH-ex333333333YLr33YaGH-ex3333Yp4fSp4h33VLc49ex3333Yp4fSp4h333BG49ex3333Yp4fWj4q33bocYBex3333Yp4fWj4q33YaGYBex33333HqWxw33333A*33333333Yp4fvmKM33cscGKex3333Yp4fvmKM33YtGGKex3333Yp4fvmLd33YycGtex3333Yp4fvmLd33YNGGtex33EEEUBNoNK2vlmEEExR4ZGXZAAexxGT3GgVXhlx3Tb3AgbehZEEEbTbbeARRAAEEE4eAeTEEEXEEExXTTx4REEEbETE3EEE4R4GTTAxXbRXeEEExXTXeGX33AEEEhv6EUBNoNKE6vgormEmgB1Ehv66vloz1E2v66vloz10VoN.hzo7oz1WWXTebeT44A03372148954dff59778daaef243e09fe\",\"dfpToken\":\"TFYoDF2mScedtgcDp7zBVdb7b___w7DDqcKXwqFnw7IZbMOwK2rCqcONBcOFw7tawqzCt8Ok\",\"operationStoreCode\":\"\",\"provinceCode\":\"190\",\"cityCode\":\"760\",\"districtCode\":\"76000\",\"townCode\":\"7600013\",\"logContent\":\"\",\"appTerminalVersions\":\"9.5.148\",\"appVersions\":\"01\",\"destLongitude\":\"113.453764\",\"destLatitude\":\"22.273928\",\"productPageType\":\"\",\"channelType\":\"02\",\"checkOrdPurFlag\":\"0\",\"poiId\":\"2773100189568760\",\"collectionType\":\"\"},\"historyReceiverInfo\":{\"addrNum\":\"2\"},\"historyPayType\":{\"payType\":\"\",\"payPeriods\":\"\"},\"immediateBuyItems\":[{\"itemHeadInfo\":{\"itemNo\":\"1\",\"activityType\":\"07\",\"activityId\":\"\"},\"mainCmmdtyInfo\":{\"basicInfo\":{\"itemNo\":\"1\",\"cmmdtyCode\":\"000000012354857650\",\"shopCode\":\"0000000000\",\"b2cShopCode\":\"\",\"shopAddCode\":\"0030004459\",\"shopName\":\"苏宁自营\",\"overSeasFlag\":\"\",\"cmmdtyQty\":\"1\",\"serviceStoreCode\":\"\",\"serviceStoreName\":\"\",\"commodityType\":\"\",\"carShopSerWay\":\"\",\"isOneHour\":\"\",\"productType\":\"\",\"platform\":\"01\"},\"collect\":[{\"collectSort\":\"10\",\"collectType\":\"13\",\"collectCode\":\"pgcate=10008;prdtp=00027;tag=四级页;pgtitle=四级页;prdid=000000012354857650;shopid=0030004459;supid=0010212008\"}]}}],\"supportYB\":\"1\",\"publishDate\":\"20240325\",\"exclusiveCouponList\":[],\"privilegeNumList\":[]}");
        Request request = new Request.Builder()
                .url("https://shopping.suning.com/app/addcart/private/quickBuy.do")
                .method("POST", body)
                .addHeader("sn_page_source", "")
                .addHeader("User-Agent", "Mozilla/5.0(Linux; U;SNEBUY-APP;9.5.148-536;SNCLIENT; Android 6.0.1; zh; OPPO R9s) AppleWebKit/533.0 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1")
                .addHeader("hiro_trace_id", "5573fbde8e8e4126a894e5fa8a69a136")
                .addHeader("snTraceId", "5573fbde8e8e4126a894e5fa8a69a136")
                .addHeader("Host", "shopping.suning.com")
                .addHeader("Cookie", getSuningCookie())
                .addHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
                .addHeader("Accept", "*/*")
                .addHeader("Connection", "keep-alive")
                .build();
        Response response = client.newCall(request).execute();
        System.out.println(response.body().string());
    }


    /**
     * 获取Suning cookie
     */
    public static String getSuningCookie() throws IOException {
        return FileUtil.readUtf8String("cookies/suning.txt");
    }
    /**
     * 获取当前服务器时间
     */
    public static String getServerTime() throws IOException {
        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        MediaType mediaType = MediaType.parse("text/plain");
        RequestBody body = RequestBody.create(mediaType, "");
        Request request = new Request.Builder()
                .url("https://product.m.suning.com/pds-web/ajax1/queryCurrentTime_.html")
                .method("GET", body)
                .addHeader("sn_page_source", "")
                .addHeader("User-Agent", "Mozilla/5.0(Linux; U;SNEBUY-APP;9.5.148-536;SNCLIENT; Android 6.0.1; zh; OPPO R9s) AppleWebKit/533.0 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1")
                .addHeader("hiro_trace_id", "792535302a624fc08f9590b5e1eeb774")
                .addHeader("snTraceId", "792535302a624fc08f9590b5e1eeb774")
                .addHeader("Host", "product.m.suning.com")
                .addHeader("Cookie", getSuningCookie())
                .addHeader("Accept", "*/*")
                .addHeader("Connection", "keep-alive")
                .build();
        Response response = client.newCall(request).execute();
        return response.body().string();
    }

}
